package com.tgd.gbb.uikit.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.tgd.gbb.uikit.R;


/**
 * 对话框
 * 
 * @Title CommonDialog.java
 * @Description 对话框
 * @author fw
 * @Crtdate 2013-11-26下午3:01:00
 */
public abstract class CommonDialog
        extends
        Dialog
{
	
	protected TextView tvText;
	protected TextView tvOk;
	protected View     vDivider;
	protected View     vCancel;
	
	private Context    context;
	protected TextView vTitle;
	
	public CommonDialog(Context context) {
		super(context, R.style.common_dialog);
		
		this.context = context;
		
		setCanceledOnTouchOutside(true);
		
		findViews();
		setListeners();
	}
	
	private void findViews() {
		View view = LayoutInflater.from(context).inflate(R.layout.common_dialog, null);
		
		tvText = (TextView) view.findViewById(R.id.common_dialog_text);
		tvOk = (TextView) view.findViewById(R.id.common_dialog_ok);
		vDivider = view.findViewById(R.id.common_dialog_divider);
		vCancel = view.findViewById(R.id.common_dialog_cancel);
		vTitle = (TextView) view.findViewById(R.id.common_dialog_title);
		
		setContentView(view);
	}
	
	private void setListeners() {
		ClickListener l = new ClickListener();
		
		tvOk.setOnClickListener(l);
		vCancel.setOnClickListener(l);
	}
	
	protected void clickOk(View v) {
		dismiss();
	}
	
	protected void clickCancel(View v) {
		dismiss();
	}
	
	private class ClickListener
	        implements
	        View.OnClickListener
	{
		
		@Override
		public void onClick(View v) {
			if(v == tvOk) {
				clickOk(v);
			} else if(v ==vCancel){
				clickCancel(v);
			}
		}
		
	}
	
}
